package common

import "fmt"

type error interface {
	Error() string
}

type Error struct {
	Type string
	Info string
	Code int
}

func NewError(message string, errorType string) *Error {
	error := new(Error)
	if errorType == "" {
		error.Type = "Error"
	} else {
		error.Type = errorType
	}
	error.Info = message
	error.Code = 500
	return error
}

func (error Error) Error() string {
	return fmt.Sprintf("error type: %s code: %d\nerror message: %s", error.Type, error.Code, error.Info)
}

const (
	RedisError = "RedisError"
	MongoError = "MongoError"
	ModelError = "ModelError"
	DataError = "DataError"
	PostError = "PostError"
	PageError = "PageError"
)